package rsj.api.contract;

import com.rlyy.aibase.utils.base.Box;
import common.util.BoxUtil;
import common.util.validator.ParameterConversionCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.contract.entity.Contract;
import rsj.api.contract.entity.ContractDetail;
import rsj.api.contract.entity.ContractParam;
import rsj.api.contract.entity.ContractStatusParam;
import rsj.log.ModuleEnum;
import rsj.log.OperationLog;
import rsj.log.OperationTypeEnum;
import rsj.service.contract.IContractService;

import java.util.List;

/**
 * 合同
 *
 * @author yuanqinglong
 * @since 2021/7/19 18:09
 */
@RestController
public class ContractController {

    @Autowired
    private IContractService contractServiceImpl;


    /**
     * 合同列表（批次详情）
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_contract_list")
    public Box contractList(Box param) {
        ContractParam contractParam = ParameterConversionCheck.parameterConversionCheckFastFail(param, ContractParam.class);
        List<ContractDetail> contracts = contractServiceImpl.contractList(contractParam.getOrgId(), contractParam.getPageInfo().getPageSize(), contractParam.getPageInfo().getPageOffSet());
        int count = contractServiceImpl.contractCount(contractParam.getOrgId());
        return BoxUtil.successBoxToTableData(param, contracts, count);
    }


    /**
     * 添加合同
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_contract_add")
    @OperationLog(description = "新增合同批次", logType = OperationTypeEnum.ADD, logModule = ModuleEnum.CONTRACT_BATCH)
    public Box addContract(Box param) {
        Contract contract = ParameterConversionCheck.parameterConversionCheckFastFail(param, Contract.class);
        contractServiceImpl.addContract(contract);
        return BoxUtil.successBox(param);
    }


    /**
     * 更新合同状态
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_contract_status_update")
    @OperationLog(description = "修改合同批次状态", logType = OperationTypeEnum.UPDATE, logModule = ModuleEnum.CONTRACT_BATCH)
    public Box updateContractStatus(Box param) {
        ContractStatusParam contractStatusParam = ParameterConversionCheck.parameterConversionCheckFastFail(param, ContractStatusParam.class);
        contractServiceImpl.updateContractStatus(contractStatusParam.getOrgpId(), contractStatusParam.getStatus());
        return BoxUtil.successBox(param);
    }

}
